package com.hebeu.device.service.impl;

import com.hebeu.device.dao.DUserRoleMapper;
import com.hebeu.device.pojo.DUserRole;
import com.hebeu.device.pojo.DUserRoleExample;
import com.hebeu.device.service.RoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色（权限）管理
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    DUserRoleMapper dUserRoleMapper;

    //查询
    @Override
    public List<DUserRole> getRole(DUserRole dUserRole) {
        DUserRoleExample dUserRoleExample = new DUserRoleExample();
        DUserRoleExample.Criteria criteria = dUserRoleExample.createCriteria();
        if(StringUtils.isNotBlank(dUserRole.getrName()))
            criteria.andRNameLike("%"+dUserRole.getrName()+"%");
        if(dUserRole.getIsEffectice()!=null)
            criteria.andIsEffecticeEqualTo(dUserRole.getIsEffectice());

    return dUserRoleMapper.selectByExample(dUserRoleExample);
    }

    //增
    @Override
    public int addRole(DUserRole dUserRole) {
        return dUserRoleMapper.insertSelective(dUserRole);
    }

    //删
    @Override
    public int delRole(DUserRole dUserRole) {
        return dUserRoleMapper.updateByPrimaryKeySelective(dUserRole);
    }

    //改
    @Override
    public int updateRole(DUserRole dUserRole) {
        return dUserRoleMapper.updateByPrimaryKeySelective(dUserRole);
    }

    //id查
    @Override
    public DUserRole getRoleById(int rId) {
        return dUserRoleMapper.selectByPrimaryKey(rId);
    }

    //通过有效查询
//    @Override
//    public DUserRole getRoleByIsEffectice(int isEffectice) {
//        System.out.println("进入Service实现层，通过有效查询");
//        return dUserRoleMapper.selectByPrimaryKey(isEffectice);
//    }
    //全查
    @Override
    public List<DUserRole> getAllRole(DUserRole dUserRole) {
        DUserRoleExample dUserRoleExample = new DUserRoleExample();
        return dUserRoleMapper.selectByExample(dUserRoleExample);
    }
}
